package com.api.gbhg.liuwenbo.version3.api;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.liuwenbo.version2.api.FinancialAppropriation2Api;
import com.api.gbhg.liuwenbo.version2.pojo.BudgetSectionIncome2;
import com.api.gbhg.liuwenbo.version3.util.ApiUtil;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 财政拨款2
 * @Version 3.0
 * @Author lwb
 * @Date
 */
@Path("v3/FinancialAppropriation2")
public class FinancialAppropriation2Api3 {

    private FinancialAppropriation2Api api = new FinancialAppropriation2Api();

    @POST
    @Path("/getDataList")
    @Produces(MediaType.APPLICATION_JSON)
    public String getDataList(Map param){
        Map msgMap = new HashMap<>();

        //检查参数是否合法
        if (!param.containsKey("nf") || !param.containsKey("jz")){
            msgMap.put("code",204);
            msgMap.put("msg","非法参数！");
            msgMap.put("data","");
            return JSON.toJSONString(msgMap);
        }
        try {
            Map<String, Object> data = api.getData(param.get("nf").toString(), param.get("jz").toString());

            Map<String,Object> resultMap = new HashMap<>();
            resultMap.put("人员经费",data.get("0"));
            resultMap.put("公用经费",data.get("1"));
            resultMap.put("项目经费", ApiUtil.structureConversion2((List<BudgetSectionIncome2>) data.get("2"),param.get("nf").toString()));


            msgMap.put("code",200);
            msgMap.put("msg","success");
            msgMap.put("data",resultMap);
        } catch (Exception e) {
            e.printStackTrace();
            msgMap.put("code",500);
            msgMap.put("msg","程序异常:"+e.toString());
            msgMap.put("data","");
            return JSON.toJSONString(msgMap);
        }
        return JSON.toJSONString(msgMap);
    }
}
